//
//  XMLaaaaaaaaa.m
//  地图显示.gpx
//
//  Created by 赵雄 on 15/10/21.
//  Copyright (c) 2015年 赵雄. All rights reserved.
//

#import "XMLaaaaaaaaa.h"
#import "wuwu.h"


@implementation XMLaaaaaaaaa


// 开始解析
-(void)start{
    NSString * path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"gpx"];
    NSURL * url = [NSURL fileURLWithPath:path];
    
    //开始解析 xml
    NSXMLParser * parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    parser.delegate = self ;
    
    [parser parse];
//    NSLog(@"%@",self.notes);
    NSLog(@"解析搞定...");
    
}
//文档开始时触发 ,开始解析时 只触发一次
-(void)parserDidStartDocument:(NSXMLParser *)parser{
    self.notes = [NSMutableArray arrayWithCapacity:0];
    self.notesTow = [NSMutableArray arrayWithCapacity:0];
}

//遇到一个开始标签触发
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    
    if ([elementName isEqualToString:@"trkpt"]) {
        self.ai = [[wuwu alloc] init];
        self.lat = [attributeDict objectForKey:@"lat"];
        self.lon = [attributeDict objectForKey:@"lon"];
    }
}

// 遇到字符串时 触发
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

}

//遇到结束标签触发
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    
    if ([elementName isEqualToString:@"trkpt"]) {
        self.ai.lat = self.lat;
        [self.notes addObject:self.lat];
        self.ai.lon = self.lon;
        [self.notesTow addObject:self.lon];

    }
}

// 结束解析
-(void)parserDidEndDocument:(NSXMLParser *)parser{

}

@end
